package com.sr.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.sr.data.*;

public class searchProject extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {		

		response.setContentType("text/html");
		baseDataService bds = new baseDataService();
		moreDataService mds = new moreDataService();
		String type = request.getParameter("type");
		//ID查询跳转
		if("byBaseID".equals(type)){
			ArrayList<srProject> al = new ArrayList<srProject>();
			String id =request.getParameter("pID");
			al.add(bds.getProjectById(id));
			request.getSession().setAttribute("baseList", al);
			request.getSession().setAttribute("ison", "byBaseID");
			response.sendRedirect("/scientific/jsp/base/baseManage.jsp");
		}
		
		//名字查询跳转
		if("byName_Base".equals(type)){
			ArrayList<srProject> al = new ArrayList<srProject>();
			String name = request.getParameter("pName");
			al = bds.GetProjectByName(name);
			request.getSession().setAttribute("baseList", al);
			request.getSession().setAttribute("ison", "byName_Base");
			response.sendRedirect("/scientific/jsp/base/baseManage.jsp");			
		}
		if("byName_More".equals(type)){
			ArrayList<srProject> al = new ArrayList<srProject>();
			String name = request.getParameter("pName");
			al = mds.getProjectByName(name);
			request.getSession().setAttribute("moreList", al);
			request.getSession().setAttribute("ison", "byName_More");
			response.sendRedirect("/scientific/jsp/more/moreManage.jsp");					
		}
		//返回全部项目
		if("allBaseInfo".equals(type)){
			ArrayList<srProject> al = new ArrayList<srProject>();
			al = bds.GetAllBase();
			request.getSession().setAttribute("baseList", al);
			request.getSession().setAttribute("ison", "allbase");
			response.sendRedirect("/scientific/jsp/base/baseManage.jsp");			
		}
		if("allMoreInfo".equals(type)){
			ArrayList<srProject> al = new ArrayList<srProject>();
			al = mds.GetMoreInfo();
			request.getSession().setAttribute("moreList", al);
			request.getSession().setAttribute("ison", "allmore");
			response.sendRedirect("/scientific/jsp/more/moreManage.jsp");			
		}
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
		this.doGet(request, response);
		
	}

	

}
